﻿using System.Collections.Generic;
using System.Net;

namespace Hourglass.Qrobot.Http
{
    public class RequestAccept
    {
        /// <summary>
        /// Http headers Accept
        /// </summary>
        public string Accept { get; set; }

        /// <summary>
        /// Http headers Accept-Encoding
        /// </summary>
        public ICollection<string> Encoding { get; set; }

        /// <summary>
        /// Http headers Accept-Language
        /// </summary>
        public ICollection<string> Language { get; set; }

        public RequestAccept()
        {
            DefaultInit();
        }

        public HttpWebRequest ApplyAccept(HttpWebRequest request)
        {
            request.Accept = Accept;
            request.Headers.Add("Accept-Language", string.Join(";", Language));
            request.Headers.Add("Accept-Encoding", string.Join(", ", Encoding));
            return request;
        }

        private void DefaultInit()
        {
            this.Accept = "*/*";
            this.Encoding = new HashSet<string> {"gzip", "deflate"};
            this.Language = new HashSet<string> {"en-US,en", "q=0.8,zh-CN"};
        }
    }
}
